home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / presto / prest1_0.lha / Tests / exer / montest.C < prev    next >
C/C++ Source or Header  |  1991-12-11  |  1KB  |  75 lines

  1. #include <stdio.h>
  2. #include <stream.h>
  3. #include "presto.h"
  4.  
  5. static shared_t int loopcount = 150;
  6.  
  7. int
  8. Main::init()
  9. {
  10.     char *progname = argv[0];
  11.     
  12.     nummainthreads = 1;
  13.     for (argc--, argv++; *argv && **argv == '-'; argv++, argc--)
  14.         switch (*(*argv + 1)) {
  15. #ifdef sequent
  16. #ifdef i386
  17.                 case 'a':
  18.                         affinity = 1;
  19.                 break;
  20. #endif /* i386 */
  21. #endif /* sequent */
  22.             case 'q':
  23.                 quantum = atoi(*argv + 2);
  24.                 break;
  25.             case 'n':
  26.                 numprocessors = atoi(*argv + 2);
  27.                 break;
  28.             case 't':
  29.                 nummainthreads = atoi(*argv + 2);
  30.                 break;
  31.             case 'l':
  32.                 loopcount = atoi(*argv + 2);
  33.                 break;
  34.             default:
  35.                 cerr << chr(*(*argv + 1)) << " unknown flag.\n";
  36.                     return -1;
  37.         }
  38.     return 0;
  39. }
  40.  
  41. static shared_t Monitor m("main_monitor");
  42. static shared_t int busy = 0;
  43.     
  44. void
  45. monitored()
  46. {
  47.     int i;
  48.  
  49.     MONITOR ENTRY(&m);
  50.     if (busy)    {
  51.         cout << "Failure.\n";
  52.         abort();
  53.     }
  54.     busy++;
  55.     for (i = 0; i < 500; i++);
  56.     loopcount--;
  57.     busy--;
  58. }
  59.  
  60. int
  61. Main::main()
  62. {
  63.     while (loopcount > 0) {
  64.         monitored();
  65.     }
  66.     return 0;
  67. }
  68.  
  69. int
  70. Main::done()
  71. {
  72.     cout << "Success.\n";
  73.     return 0;
  74. }
  75.